home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!milyng
- From: mikael@pobox.com (Mikael Lyngvig)
- Subject: Re: Escape Sequences in c++
- Message-ID: <milyngDM8JFq.LKv@netcom.com>
- Sender: milyng@netcom9.netcom.com
- Organization: Hacker's Paradise, Inc.
- X-Newsreader: WinVN 0.99.7
- References: <3113aa29.14180305@news.flex.net>
- Date: Sun, 4 Feb 1996 05:04:37 GMT
-
- In article <3113aa29.14180305@news.flex.net>, Awitas@flex.net says...
-
- > Does anyone know how to use the Ansi.sys escape sequences in
- >c++? Specifically the cursor-control sequences. Any help would be
- >greatly appreciated.
-
- Assuming you have ANSI.SYS installed, you can just write them to 'stdout'
- (the default output device when you use C's standard I/O library):
-
- #include <stdio.h>
-
- int main(int argc, const char *argv[])
- {
- FILE *pOutput;
-
- ...
-
- printf("\x1B[1;33;44m%s: %s\x1B[0m\n", DateStr, EventStr);
-
- pOutput = stdout;
- fprintf(pOutput, "\x1B[1;33;44m%s: %s\x1B[0m\n", DateStr, EventStr);
- }
-
- I think the escape sequence shown displays the current date and a so-called
- event (a string) using white ink on blue paper (mm.dd.yy: string). \x1B is
- the Escape character that marks the beginning of an ANSI escape sequence and
- so on. The example mixes hexadecimal C escape sequences (\xNN) with clear
- text characters ([), but it would probably be a good idea to isolate it
- somehow and have specific functions such as "SetInkColor(WHITE);
- SetPaperColor(BLUE);" etc., so you can easily change it to not use ANSI later
- on (when you discover that very few systems support ANSI and not all users
- have ANSI.SYS installed :).
-
- This is code from a program I wrote years back, but it illustrates the
- concept; the two statements are functionally identical (I recommend using the
- second method because it gives you the option of dumping the stuff to a file
- for debugging purposes etc.).
-
-
- Mikael
-
-